package org.Game;

import java.util.ArrayList;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

import com.example.gameex2.SpriteAnimation;
import org.Game.*;

public class Player{
	public SpriteAnimation m_Top;
	public SpriteAnimation m_Base;
	private double m_fBaseRotate = 0.0f;
	private double m_fTopRotate = 0.0f;
	
	float m_StrikingPower;
	float m_DefensivePower;

	float m_AttackSpeed;	
	float m_MovementSpeed;
	
	protected Rect m_BoundBox = new Rect(); 
		
	ArrayList<ItemEquipment> m_PlaterHaveItemEqupment = new ArrayList<ItemEquipment>();

	
	public void SetBitmap(Bitmap top, Bitmap base)
	{
		m_Top = new SpriteAnimation(top);
		m_Base = new SpriteAnimation(base);
	}
	
	public int GetX()
	{
		return m_Base.GetX();
	}
	
	public int GetY()
	{
		return m_Base.GetY();
	}
	
	public void InitTopSprite(int left, int top, int width, int height, int fps, int iFrame)
	{
		m_Top.InitSpriteData(left, top, width, height, fps, iFrame);
		
		m_Top.SetPosition(600, 300);
		
		InitialStatus();
	}
	
	public void InitBottomSprite(int left, int top, int width, int height, int fps, int iFrame)
	{
		m_Base.InitSpriteData(left, top, width, height, fps, iFrame);
		
		m_Base.SetPosition(600, 300);
		
		m_BoundBox.set(m_Base.GetX(), m_Base.GetY(), m_Base.GetX() + m_Base.GetBitmap().getWidth(), m_Base.GetY() + m_Base.GetBitmap().getHeight());
	}
	
	public void Update() {
		// TODO Auto-generated method stub
		long GameTime = System.currentTimeMillis();
		m_Top.Update(GameTime);
		m_Base.Update(GameTime);
		
		
	}

	public void Draw(Canvas canvas) {
		// TODO Auto-generated method stub
		m_Base.DrawRotate(canvas, m_fBaseRotate);
		m_Top.DrawRotate(canvas, m_fTopRotate);
	}
	
	public void MoveBase(int CenterX, int CenterY, float x, float y)
	{
	
		int CrrentX = CenterX;
		int CrrentY = CenterY;
		Vector2 direction = new Vector2(x - CrrentX, y - CrrentY);
		Vector2.Normalize(direction);
		m_fBaseRotate = Vector2.Dot(direction, new Vector2(1.0f, 0.0f));
		m_fBaseRotate = Math.toDegrees(Math.acos(m_fBaseRotate));
		if(y < CrrentY)
			m_fBaseRotate = -m_fBaseRotate;
	}
	
	public void RotateTop(float x, float y)
	{
		int CrrentX = m_Top.GetCenterX();
		int CrrentY = m_Top.GetCenterY();
		Vector2 direction = new Vector2(x - CrrentX, y - CrrentY);
		Vector2.Normalize(direction);
		m_fTopRotate = Vector2.Dot(direction, new Vector2(1.0f, 0.0f));
		m_fTopRotate = Math.toDegrees(Math.acos(m_fTopRotate));
		if(y < CrrentY)
			m_fTopRotate = -m_fTopRotate;
	}
	
	void InitialStatus()
	{
		m_StrikingPower = 1.0f;
		m_DefensivePower = 1.0f;
		m_AttackSpeed = 1.0f;	
		m_MovementSpeed = 0.1f;
	}
	
	void AddItemEqupment(ItemEquipment AddItem)
	{
		m_PlaterHaveItemEqupment.add(AddItem);
		
		m_StrikingPower += AddItem.m_StrikingPower;
		m_DefensivePower += AddItem.m_DefensivePower;
		m_AttackSpeed += AddItem.m_AttackSpeed;	
		m_MovementSpeed += AddItem.m_MovementSpeed;
		
	}
	
}
